package com.ruoyi.violation.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.manger.domain.RegulationConfig;
import com.ruoyi.manger.mapper.RegulationConfigMapper;
import com.ruoyi.violation.vo.CorrectVo;
import com.ruoyi.violation.vo.LawAuditVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.violation.mapper.VehicleViolationReportMapper;
import com.ruoyi.violation.domain.VehicleViolationReport;
import com.ruoyi.violation.service.IVehicleViolationReportService;

/**
 * 车辆违章上报信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-12-14
 */
@Service
public class VehicleViolationReportServiceImpl implements IVehicleViolationReportService 
{
    @Autowired
    private VehicleViolationReportMapper vehicleViolationReportMapper;


    @Autowired
    private RegulationConfigMapper regulationConfigMapper;

    /**
     * 查询车辆违章上报信息
     * 
     * @param id 车辆违章上报信息主键
     * @return 车辆违章上报信息
     */
    @Override
    public VehicleViolationReport selectVehicleViolationReportById(Long id)
    {
        return vehicleViolationReportMapper.selectVehicleViolationReportById(id);
    }

    /**
     * 查询车辆违章上报信息列表
     * 
     * @param vehicleViolationReport 车辆违章上报信息
     * @return 车辆违章上报信息
     */
    @Override
    public List<VehicleViolationReport> selectVehicleViolationReportList(VehicleViolationReport vehicleViolationReport)
    {

        List<VehicleViolationReport> list = vehicleViolationReportMapper.selectVehicleViolationReportList(vehicleViolationReport);
        list.forEach(item->{
            RegulationConfig config = regulationConfigMapper.selectRegulationConfigById(item.getVehiceViolationId());
            item.setRegulationsTitle(config.getRegulationsTitle());
        });
        return list;
    }

    /**
     * 新增车辆违章上报信息
     * 
     * @param vehicleViolationReport 车辆违章上报信息
     * @return 结果
     */
    @Override
    public int insertVehicleViolationReport(VehicleViolationReport vehicleViolationReport)
    {
        vehicleViolationReport.setCreateTime(DateUtils.getNowDate());
        vehicleViolationReport.setPenaltyTime(DateUtils.getNowDate());
        vehicleViolationReport.setViolationTime(DateUtils.getNowDate());
        return vehicleViolationReportMapper.insertVehicleViolationReport(vehicleViolationReport);
    }

    /**
     * 修改车辆违章上报信息
     * 
     * @param vehicleViolationReport 车辆违章上报信息
     * @return 结果
     */
    @Override
    public int updateVehicleViolationReport(VehicleViolationReport vehicleViolationReport)
    {
        vehicleViolationReport.setUpdateTime(DateUtils.getNowDate());
        return vehicleViolationReportMapper.updateVehicleViolationReport(vehicleViolationReport);
    }

    /**
     * 批量删除车辆违章上报信息
     * 
     * @param ids 需要删除的车辆违章上报信息主键
     * @return 结果
     */
    @Override
    public int deleteVehicleViolationReportByIds(Long[] ids)
    {
        return vehicleViolationReportMapper.deleteVehicleViolationReportByIds(ids);
    }

    /**
     * 删除车辆违章上报信息信息
     * 
     * @param id 车辆违章上报信息主键
     * @return 结果
     */
    @Override
    public int deleteVehicleViolationReportById(Long id)
    {
        return vehicleViolationReportMapper.deleteVehicleViolationReportById(id);
    }

    @Override
    public int removeVehicleViolationReportByIds(Long[] ids) {
        return vehicleViolationReportMapper.removeVehicleViolationReportByIds(ids);
    }

    @Override
    public int audit(LawAuditVo lawAuditVo) {
        VehicleViolationReport vehicleViolationReport  =vehicleViolationReportMapper.selectVehicleViolationReportById(lawAuditVo.getId());
        vehicleViolationReport.setAuditUserId(lawAuditVo.getAuditUserId()+"");
        vehicleViolationReport.setAuditReason(lawAuditVo.getReason());
        vehicleViolationReport.setAuditStatus(lawAuditVo.getAuditStatus()+"");
        return vehicleViolationReportMapper.updateVehicleViolationReport(vehicleViolationReport);
    }

    @Override
    public int correct(CorrectVo correctVo) {
        Long id = correctVo.getId();
        VehicleViolationReport vehicleViolationReport = vehicleViolationReportMapper.selectVehicleViolationReportById(id);
        vehicleViolationReport.setHandleImgUrl(correctVo.getImgUrl());
        vehicleViolationReport.setHandleContent(correctVo.getContent());
        return vehicleViolationReportMapper.updateVehicleViolationReport(vehicleViolationReport);
    }
}
